/*
 * @Copyright: 2016 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.data.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;

import com.yyfax.framework.dao.impl.BaseDaoImpl;
import com.yyfax.pay.order.data.dao.PayinOrderLogDao;
import com.yyfax.pay.order.model.po.PayinBatchOrderLogPO;
import com.yyfax.pay.order.model.po.PayinOrderLogPO;
import com.yyfax.pay.order.model.po.PayinOrderLogPO;

/**
 * 代扣日志持久化实现
 *
 * @author maojian
 * @date 2017年04月12日 11:09:15
 * @since 1.0.0
 */
@Repository
public class PayinOrderLogDaoImpl extends BaseDaoImpl<PayinOrderLogPO, Integer> implements PayinOrderLogDao {
	private static final String TABLE_NAME = "payin_order_log";

	private final String SQL_INSERT = "insert";
	
	private final String SQL_SELECT_LIST_BY_ORDERID = "selectListByOrderId";
	
	private final String SQL_SELECT_LIST = "selectListByPayinOrderId";

	public PayinOrderLogDaoImpl() {
		super(TABLE_NAME);
	}

	@Override
	public int insert(PayinOrderLogPO po) {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_INSERT);
		BeanPropertySqlParameterSource sqlParameterSource = new BeanPropertySqlParameterSource(po);
		return namedParameterJdbcTemplate.update(sql, sqlParameterSource);
	}


	/**
	 * 查询列表
	 * 
	 * @author maojian
	 * @date 2017-04-26 11:00:52
	 * @since v1.0.0
	 *
	 * @param merchantCode
	 * @param orderId
	 * @return
	 */
	public List<PayinOrderLogPO> selectListByOrderId(String merchantCode, String orderId){
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_SELECT_LIST_BY_ORDERID);
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("merchantCode", merchantCode);
		params.addValue("orderId", orderId);
		return namedParameterJdbcTemplate.query(sql, params, new BeanPropertyRowMapper<PayinOrderLogPO>(poClass));
	}

	@Override
	public List<PayinOrderLogPO> selectListByPayinOrderId(String payinOrderId,
			String merchantCode) {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_SELECT_LIST);
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("payinOrderId", payinOrderId);
		params.addValue("merchantCode", merchantCode);
		return namedParameterJdbcTemplate.query(sql, params, new BeanPropertyRowMapper<PayinOrderLogPO>(poClass));
	}
}
